package com.xperblueray.stepbystep.quartz;

import com.xperblueray.stepbystep.mail.SendJunkMailService;
import com.xperblueray.stepbystep.model.SysDict;
import com.xperblueray.stepbystep.service.SysDictService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

@Component
@Configurable
@EnableScheduling
public class SendMailQuartz {
    // 日志对象
    Logger logger = LogManager.getLogger(this.getClass());
    @Resource
    SysDictService sysDictService;

    @Resource
    SendJunkMailService sendJunkMailService;

    // 每5s执行一次
    @Scheduled(cron = "*/5 * * * * * ")
    public void reportCurrentByCron() {
        logger.info("注解定时器执行！！！");
    }

    // 每5s执行一次
    @Scheduled(cron = "*/5 * * * * * ")
    public void reportCurrentByCronSendEmail() {
        List<SysDict> infos = sysDictService.findAll();
        if(!CollectionUtils.isEmpty(infos)) {
//            sendJunkMailService.sendJunkMail(infos);
        }
        logger.info("注解定时器执行！！！");
    }


}
